<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<p:dialog xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	modal="true" width="930" height="560" resizable="false" 
	widgetVar="dialogAddFornecedor" id="dialogFornecedor" closable="false"
	appendToBody="true">

	<link type="text/css" rel="stylesheet" href="../../resources/css/style.css" />
	
	<f:facet name="header">
		<h:outputText value="Cadastrar Fornecedor" />
	</f:facet>
	
	<h:form id="formAddFornecedor" prependId="false">
		<h:panelGroup id="panelFornecedor">
			<p:panel>
				<p:messages id="messageFormFornecedor" closable="true"/>
				<div>
					<p:selectOneRadio id="option2" value="#{compraBean.newFornecedor.tipoPessoa}" immediate="true" 
						rendered="#{compraBean.newFornecedor.id == null}" >					
						<f:selectItems value="#{compraBean.tiposPessoa}"/>
						<f:ajax event="change" render="renderForm"  />
					</p:selectOneRadio>
					
					<p:outputPanel id="renderForm">
						<h:panelGrid columns="3" style="padding:5px;" rendered="#{compraBean.newFornecedor.tipoPessoa == 'JURIDICA'}">
							<h:outputText value="Código" />
							<h:outputText value="Razão social" />
							<h:outputText value="Nome fantasia *" />
		
							<p:inputText style="width:100px;" disabled="true" value="#{compraBean.newFornecedor.id}"/>
							<p:inputText style="width:350px;" value="#{compraBean.newFornecedor.razaoSocial}" maxlength="100"/>
							<p:inputText style="width:350px;" value="#{compraBean.newFornecedor.nome}" maxlength="100"
								required="#{compraBean.newFornecedor.tipoPessoa == 'JURIDICA'}" requiredMessage="Informe o nome fantasia."/>
						</h:panelGrid>
						
						<h:panelGrid columns="3" style="padding:5px;" rendered="#{compraBean.newFornecedor.tipoPessoa == 'FISICA'}">
							<h:outputText value="Código" />
							<h:outputText value="Nome completo *" />
							<h:outputText value="Apelido" />
		
							<p:inputText style="width:100px;" disabled="true" value="#{compraBean.newFornecedor.id}"/>
							<p:inputText style="width:350px;" value="#{compraBean.newFornecedor.nome}" maxlength="100"
								required="#{compraBean.newFornecedor.tipoPessoa == 'FISICA'}" requiredMessage="Informe o nome completo."/>
							<p:inputText style="width:350px;" value="#{compraBean.newFornecedor.apelido}" maxlength="50"/>
						</h:panelGrid>
						
						<h:panelGrid columns="4" style="padding:5px;">
							<h:outputText value="Logradouro *" />
							<h:outputText value="Número *" />
							<h:outputText value="Complemento" />
							<h:outputText value="Bairro *" />
		
							<p:inputText style="width:350px;" value="#{compraBean.newFornecedor.logradouro}" maxlength="40" required="true" requiredMessage="Informe o logradouro."/>
							<p:inputText style="width:80px;" value="#{compraBean.newFornecedor.numero}" maxlength="10" required="true" requiredMessage="Informe o número."/>
							<p:inputText style="width:150px;" value="#{compraBean.newFornecedor.complemento}" maxlength="20"/>
							<p:inputText style="width:200px;" value="#{compraBean.newFornecedor.bairro}" maxlength="20" required="true" requiredMessage="Informe o bairro."/>
						</h:panelGrid>
						
						<h:panelGrid columns="5" style="padding:5px;" id="panelLocal">
							<h:outputText value="CEP" />
							<h:outputText value="Cidade *" />
							<h:outputText value="Estado" />
							<h:outputText value="País" />
							<h:outputText value="" />
		
							<p:inputMask mask="99.999-999" style="width:150px;" value="#{compraBean.newFornecedor.cep}"/>
							
							<p:autoComplete id="inputCidade" var="cidade" value="#{compraBean.newFornecedor.cidade}" maxlength="30"
								itemLabel="#{cidade.cidade}" itemValue="#{cidade}" size="50" required="true" requiredMessage="Selecione a cidade."
								converter="cidadeConverter" completeMethod="#{compraBean.getCidadeByQuery}">
								<p:ajax event="itemSelect" process="@this inputCidade" update="inputEstado inputPais inputDDDTel inputDDDCel"/>
							</p:autoComplete>
							
							<p:inputText style="width:200px;" disabled="true" value="#{compraBean.newFornecedor.cidade.estado.estado}" id="inputEstado"/>
							<p:inputText style="width:150px;" disabled="true" value="#{compraBean.newFornecedor.cidade.estado.pais.pais}" id="inputPais"/>
							<p:commandButton icon="ui-icon-search" style="height:24px;" actionListener="#{compraBean.openDialogListCidade}" immediate="true" title="Selecionar cidade"/>
						</h:panelGrid>
	
						<h:panelGrid columns="5" style="padding:5px;" id="panelContato">
							<h:outputText value="Telefone" />
							<h:outputText value="" />
							<h:outputText value="Fax" />
							<h:outputText value="" />
							<h:outputText value="Site" />
		
							<p:inputMask mask="9?9" style="width:50px;" value="#{compraBean.newFornecedor.cidade.ddd}" id="inputDDDTel" maxlength="2" placeHolder=" "/>
							<p:inputMask mask="9999-9999" style="width:150px;" value="#{compraBean.newFornecedor.telefone}"/>
							<p:inputMask mask="9?9" style="width:50px;"  value="#{compraBean.newFornecedor.cidade.ddd}" id="inputDDDCel" maxlength="2" placeHolder=" "/> 
							<p:inputMask mask="9999-9999" style="width:150px;" value="#{compraBean.newFornecedor.fax}"/>
							<p:inputText style="width:350px;" value="#{compraBean.newFornecedor.site}" maxlength="100"/>
						</h:panelGrid>
						<h:panelGrid columns="4" style="padding:5px;">
							<h:outputText value="E-mail" />
							<h:outputText value="Pessoa para contato" />
							<h:outputText value="Telefone" />
							<h:outputText value="" />
		
							<p:inputText style="width:300px;" value="#{compraBean.newFornecedor.emailContato}" maxlength="50"/>
							<p:inputText style="width:250px;" value="#{compraBean.newFornecedor.nomeContato}" maxlength="50"/>
							<p:inputMask mask="9?9" style="width:50px;" value="#{compraBean.newFornecedor.dddContato}" maxlength="2" placeHolder=" "/>
							<p:inputMask mask="9999-9999" style="width:150px;" value="#{compraBean.newFornecedor.telContato}"/>
						</h:panelGrid>
						<h:panelGrid columns="2" style="padding:5px;" rendered="#{compraBean.newFornecedor.tipoPessoa == 'JURIDICA'}">
							<h:outputText value="Inscrição estadual" />
							<h:outputText value="CNPJ" />
		
							<p:inputText style="width:150px;" value="#{compraBean.newFornecedor.inscricaoEstadual}" maxlength="20"/>
							<p:inputMask mask="99.999.999./9999-99" style="width:150px;" value="#{compraBean.newFornecedor.cnpj}"/>
						</h:panelGrid>			
	
						<h:panelGrid columns="2" style="padding:5px;" rendered="#{compraBean.newFornecedor.tipoPessoa == 'FISICA'}">
							<h:outputText value="RG" />
							<h:outputText value="CPF" />
		
							<p:inputText style="width:150px;" value="#{compraBean.newFornecedor.rg}" maxlength="20"/>
							<p:inputMask mask="999.999.999-99" value="#{compraBean.newFornecedor.cpf}" maxlength="11" style="width:150px;"/>
						</h:panelGrid>
						
						<h:panelGrid columns="1" style="padding:5px;">
							<h:outputText value="* Campos obrigatórios" />
						</h:panelGrid>
					</p:outputPanel>
				</div>
			</p:panel>
		
		<div id="popup-buttons" style="padding-bottom: 10px; padding-top: 10px; text-align: right;">
			<p:commandButton value="Salvar" style="height:28px;" actionListener="#{compraBean.saveFornecedorFromDialog}" process="@this panelFornecedor" update="panelFornecedor" icon="ui-icon-disk"/>
			<p:commandButton value="Cancelar" style="height:28px;" onclick="dialogAddFornecedor.hide()" immediate="true" icon="ui-icon-cancel"/>
		</div>
		</h:panelGroup>
	</h:form>
</p:dialog>